package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.ZfbConfigVo;
import org.dromara.system.domain.bo.ZfbConfigBo;
import org.dromara.system.service.IZfbConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 支付宝
 *
 * @author Lion Li
 * @date 2025-07-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/ZfbConfig")
public class ZfbConfigController extends BaseController {

    private final IZfbConfigService zfbConfigService;

    /**
     * 查询支付宝列表
     */
    @SaCheckPermission("system:config:list")
    @GetMapping("/list")
    public TableDataInfo<ZfbConfigVo> list(ZfbConfigBo bo, PageQuery pageQuery) {
        return zfbConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出支付宝列表
     */
    @SaCheckPermission("system:config:export")
    @Log(title = "支付宝", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZfbConfigBo bo, HttpServletResponse response) {
        List<ZfbConfigVo> list = zfbConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "支付宝", ZfbConfigVo.class, response);
    }

    /**
     * 获取支付宝详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:config:query")
    @GetMapping("/{id}")
    public R<ZfbConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(zfbConfigService.queryById(id));
    }

    /**
     * 新增支付宝
     */
    @SaCheckPermission("system:config:add")
    @Log(title = "支付宝", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZfbConfigBo bo) {
        return toAjax(zfbConfigService.insertByBo(bo));
    }

    /**
     * 修改支付宝
     */
    @SaCheckPermission("system:config:edit")
    @Log(title = "支付宝", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZfbConfigBo bo) {
        return toAjax(zfbConfigService.updateByBo(bo));
    }

    /**
     * 删除支付宝
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:config:remove")
    @Log(title = "支付宝", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(zfbConfigService.deleteWithValidByIds(List.of(ids), true));
    }
}
